﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class AnswerInChannelFormFieldsController : ControllerBase
    {

        private readonly IAnswerInChannelFormFieldAppService _app;
        public AnswerInChannelFormFieldsController(IAnswerInChannelFormFieldAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("fields/{id:Guid}")]
        public ActionResult<AnswerInChannelFormFieldDto> Get([FromRoute] Guid id, [FromQuery] string include="")
        {
            AnswerInChannelFormFieldDto answerInChannelFormField = _app.Get(id,include);
            return Ok(answerInChannelFormField);
        }

        [HttpGet]
        [Route("forms/{formId:Guid}/fields")]
        public ActionResult<IEnumerable<AnswerInChannelFormFieldDto>> GetList([FromRoute] Guid formId, [FromQuery]string include = "")
        {
            IEnumerable<AnswerInChannelFormFieldDto> list = _app.GetList(formId, include);
            return Ok(list);
        }

        [HttpPut]
        [Route("fields/{id:Guid}")]
        public ActionResult<AnswerInChannelFormFieldDto> Put([FromRoute] Guid id, [FromBody] AnswerInChannelFormFieldUpdateDto dto)
        {
            AnswerInChannelFormFieldDto answerInChannelFormField = _app.Update(id, dto);
            return Ok(answerInChannelFormField);
        }

        [HttpPost]
        [Route("forms/{formId:Guid}/fields")]
        public ActionResult<AnswerInChannelFormFieldDto> Post([FromRoute] Guid formId, [FromBody] AnswerInChannelFormFieldCreateDto dto)
        {
            AnswerInChannelFormFieldDto answerInChannelFormField = _app.Add(formId,dto);
            return CreatedAtAction(nameof(Get), new { id = answerInChannelFormField.Id }, answerInChannelFormField);
        }

        [HttpDelete]
        [Route("fields/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
